import serial
import serial.tools.list_ports

class Ports(object):
	def __init__(self):
		self.get_ports()

	def get_ports(self):
		self.port_list = list(serial.tools.list_ports.comports())
		self.port_name = []
		for port in self.port_list:
			self.port_name.append(port.device)
		return self.port_name

	def init_port(self, index=0):
		self.port = self.port_name[index]
		self.serial = serial.Serial(
			port=self.port, baudrate=9600, bytesize=8, parity='N', 
			stopbits=1)

	def set_port(self, port):
		self.port = port
		self.init_port()

	def set_baudrate(self, i):
		baudrates = [14400, 38400, 115200]
		self.serial.set_baudrate(baudrates[i])

	def set_parity(self, i):
		PARITIES = ('N', 'E', 'O', 'M', 'S') #"M = mark(1) parity" 
		self.serial.set_parity(PARITIES[i])

	def set_stopbits(self, i):
		STOPBITS = (1, 1.5, 2)
		self.serial.set_parity(STOPBITS[i])

	def set_bytesize(self, i):
		BYTESIZES = (5, 6, 7, 8) 
		self.serial.set_bytesize(BYTESIZES[I])

print(serial.PARITY_EVEN)



